package cn.tedu.basic;
//测试单例设计模式
public class Test7 {
    public static void main(String[] args) {
      MoTe mt1 = MoTe.getMoTe();
      MoTe mt2 = MoTe.getMoTe();
        System.out.println(mt1==mt2);
    }
}
//饿汉式
class MoTe{
    private MoTe(){}
    private static MoTe mt =new MoTe();
    public static MoTe getMoTe(){
        return mt;
    }
}
class Teacher{
    private Teacher(){}
    private static Teacher tea =new Teacher();
    public static Teacher getTeacher(){
        return tea;
    }
}
//懒汉式
class Doctor{
    private Doctor(){}
    private static Doctor doc;
   synchronized public static Doctor getDoctor(){
        if (doc==null){
            doc=new Doctor();
        }
        return doc;
    }
}
class KongJie{
    private KongJie(){}
    private static KongJie kj ;
    synchronized public static KongJie getKongJie(){
        if (kj==null){
            kj=new KongJie();
        }
        return kj;
    }
}